﻿namespace Sidvall.Business
{
    public class BusinessException : System.Exception
    {
        #region Public Members

        public string Title { get; set; }
        public string ErrorCode { get; set; }

        #region GetMessageResolved

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public string GetMessageResolved()
        {
            if (!string.IsNullOrWhiteSpace(this.Message))
                return this.Message;
            else
                return Sidvall.Resources.ResourceKeyManager.Current.BusinessExceptionMessage;
        }

        #endregion
        #region GetTitleResolved

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public string GetTitleResolved()
        {
            if (!string.IsNullOrWhiteSpace(this.Title))
                return this.Title;
            else
                return Sidvall.Resources.ResourceKeyManager.Current.UnexpectedExceptionTitle;
        }

        #endregion

        #endregion
        #region Constructors

        public BusinessException()
        {
        }
        public BusinessException(BusinessExceptionContext context) : base(context?.Message)
        {
            this.Title = context?.Title;
            this.ErrorCode = context?.ErrorCode;
        }
        public BusinessException(string message) : base(message)
        {
        }
        public BusinessException(string message, string title, string errorCode) : base(message)
        {
            this.Title = title;
            this.ErrorCode = errorCode;
        }
        public BusinessException(string message, System.Exception innerException) : base(message, innerException)
        {
        }

        #endregion
    }
}
